/* eslint-disable */
import axios from 'axios';

const baseUrl = 'http://47.111.104.30:8080'; 

class HttpRequest {
    constructor(baseUrl) {
        this.baseUrl = baseUrl;
    }

    getInsideConfig() {
        const config = {
            baseURL: this.baseUrl,
            headers: {
                'Content-Type': 'application/json',
                'Authorization': `Bearer ${localStorage.getItem('token') || ''}` // 防止 null
            },
            withCredentials: true
        };
        return config;
    }

    interception(instance) {
        instance.interceptors.request.use(
            config => {
                // 可以在这里加 loading 等逻辑
                return config;
            },
            error => Promise.reject(error)
        );

        instance.interceptors.response.use(
            response => response.data, 
            error => {
                // 可做错误弹窗统一处理
                console.error('请求出错：', error);
                return Promise.reject(error);
            }
        );
    }

    request(options) {
        const instance = axios.create();
        const config = { ...this.getInsideConfig(), ...options };
        this.interception(instance);
        return instance(config);
    }
}

export default new HttpRequest(baseUrl);
